package xyf.p11.other.prepoststatistics;

/**
 * ClassName: P0121_MaxProfit
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:16 AM
 * Version: 1.0
 **/
public class P0121_MaxProfit
{
    public int maxProfit(int[] prices)
    {
        int min = prices[0];
        int maxProfit = 0;
        for (int i = 1; i < prices.length; i++)
        {
            if (prices[i] < min)
            {
                min = prices[i];
                continue;
            }
            int curProfit = prices[i] - min;
            maxProfit = Math.max(maxProfit, curProfit);
        }
        return maxProfit;
    }
}
